package com.test.byteDance;

import com.review.test.Solution;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Byte2019_7 {
    public int minPower(int[] power) {
        int max = Integer.MIN_VALUE;
        for (int i : power) {
            max = Math.max(max, i);
        }
        for (int i = 1; i <= max; i++) {
            if (check(power, i)) {
                return i;
            }
        }
        return 0;
    }

    public boolean check(int[] power, int start) {
        for (int value : power) {
            start = 2 * start - value;
            if (start < 0) {
                return false;
            }
        }
        return true;
    }
}

class Main_3 {
    public static void main(String[] args) {
        /*Scanner scanner = new Scanner(System.in);
        Byte2019_7 byte2019_7 = new Byte2019_7();
        int start = scanner.nextInt();
        int[] power = new int[start];
        for (int i = 0; i < start; i++) {
            power[i] = scanner.nextInt();
        }
        System.out.println(byte2019_7.minPower(power));*/

        /*Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        List<int[][]> list = new ArrayList<>();
        for (int i = 0; i < T; i++){
            int M = scanner.nextInt();
            int N = scanner.nextInt();
            int[][] landMap = new int[M][N];
            for (int j = 0; j < M; j++) {
                char[] chars = scanner.next().toCharArray();
                for (int k = 0; k < N; k++){
                    landMap[j][k] = chars[k]-'0';
                }
            }
            // 将一张张潮水图存到landMap里
            list.add(landMap);
        }
        for (int[][] ints : list) {
            for (int[] anInt : ints) {
                for (int i : anInt) {
                    System.out.print(i);
                }
            }
        }*/

        //Solution s = new Solution();
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        // 用于盛放结果集
        int[] res = new int[T];
        for (int i = 0; i<res.length; i++){
            int N = sc.nextInt();
            // 有多少桶
            boolean flag = true;
            for(int j = 0;j<N;j++){
                int K_i = sc.nextInt();
                // 桶里几个球
                int[] bolls = new int[K_i];
                for(int k = 0;k<K_i;k++){
                    bolls[k] = sc.nextInt();
                }
                // 验证当前桶球是否合规的逻辑判断
                //flag = flag&&s.checkBoll(bolls);
            }
            if(flag) res[i] = 1;
        }
        for(int tmp : res){
            System.out.println(tmp);
        }
    }
}
